<template>
  <div>
    <el-form-item label="选项标题">
      <el-input v-model="localData.content" placeholder="请输入选项标题" />
    </el-form-item>
    <el-form-item label="选中时值">
      <el-input v-model="localData.trueValue" placeholder="请输入选中时值" />
    </el-form-item>
    <el-form-item label="未选中时值">
      <el-input v-model="localData.falseValue" placeholder="请输入未选中时值" />
    </el-form-item>
    <el-form-item label="显示边框">
      <el-switch v-model="localData.border" />
    </el-form-item>
    <el-form-item label="标题绑定属性">
      <el-cascader
        :props="CascaderProps"
        :options="attrList"
        v-model="localData.bindLabel"
        placeholder="请选择属性"
        filterable
        clearable
        :show-all-levels="false"
      >
        <template #default="{ data: opt }">
          <span>{{ `${opt.entityDesc}(${opt.entityName})` }}</span>
        </template>
      </el-cascader>
    </el-form-item>
  </div>
</template>

<script>
export default {
  name: 'SingelCheckboxConfig',
  props: {
    data: {
      type: Object,
      default: () => {}
    },
    attrList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      localData: {},
      CascaderProps: {
        value: 'entityName',
        label: 'entityDescName',
        children: 'childList',
        emitPath: false
      },
    }
  },
  watch: {
    data: {
      handler(newVal) {
        if (newVal) {
          this.localData = newVal
        }
      },
      deep: true,
      immediate: true
    },
    localData: {
      handler(newVal) {
        this.$emit('update:data', newVal)
      },
      deep: true
    }
  }
}
</script>
